home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / netinclude / net / route.h < prev    next >
C/C++ Source or Header  |  1993-08-12  |  12KB  |  311 lines

  1. /* $Id: route.h,v 1.9 1993/06/04 11:16:15 jraja Exp $
  2.  *
  3.  * Copyright (c) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>,
  4.  *                    Helsinki University of Technology, Finland.
  5.  *                    All rights reserved.
  6.  *
  7.  * route.h --- Generic Routing Routines
  8.  *
  9.  * Last modified: Fri Jun  4 00:39:43 1993 jraja
  10.  *
  11.  * HISTORY
  12.  * $Log: route.h,v $
  13.  * Revision 1.9  1993/06/04  11:16:15  jraja
  14.  * Fixes for first public release.
  15.  *
  16.  * Revision 1.8  1993/05/29  20:44:42  jraja
  17.  * Removed obsolete definitions.
  18.  *
  19.  * Revision 1.7  1993/05/16  21:09:43  ppessi
  20.  * RCS version changed.
  21.  *
  22.  * Revision 1.6  1993/05/03  10:26:28  jraja
  23.  *  Put some KERNEL specific definitions inside #ifdef KERNEL ... #endif
  24.  *
  25.  * Revision 1.5  93/05/02  17:32:02  17:32:02  jraja (Jarno Tapio Rajahalme)
  26.  * Removed some obsolete definitions,
  27.  * included protos from distinct proto file here.
  28.  * 
  29.  * Revision 1.4  93/04/05  17:47:28  17:47:28  jraja (Jarno Tapio Rajahalme)
  30.  * Commneted out #include <gateway.h> since every c-file includes
  31.  * conf.h which contains the definition for GATEWAY.
  32.  * 
  33.  * Revision 1.3  93/03/05  03:12:54  03:12:54  ppessi (Pekka Pessi)
  34.  * Compiles with SASC. Initial test version
  35.  * 
  36.  * Revision 1.2  93/02/25  16:50:25  16:50:25  jraja (Jarno Tapio Rajahalme)
  37.  * added inclusion of route prototypes at the end of the file.
  38.  * 
  39.  * Revision 1.1  92/11/20  14:59:28  14:59:28  jraja (Jarno Tapio Rajahalme)
  40.  * Initial revision
  41.  * 
  42.  *
  43.  */
  44.  
  45. /* 
  46.  * Mach Operating System
  47.  * Copyright (c) 1992 Carnegie Mellon University
  48.  * All Rights Reserved.
  49.  * 
  50.  * Permission to use, copy, modify and distribute this software and its
  51.  * documentation is hereby granted, provided that both the copyright
  52.  * notice and this permission notice appear in all copies of the
  53.  * software, derivative works or modified versions, and any portions
  54.  * thereof, and that both notices appear in supporting documentation.
  55.  * 
  56.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  57.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  58.  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  59.  * 
  60.  * Carnegie Mellon requests users of this software to return to
  61.  * 
  62.  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
  63.  *  School of Computer Science
  64.  *  Carnegie Mellon University
  65.  *  Pittsburgh PA 15213-3890
  66.  * 
  67.  * any improvements or extensions that they make and grant Carnegie Mellon 
  68.  * the rights to redistribute these changes.
  69.  */
  70. /*
  71.  * HISTORY
  72.  * Log:    route.h,v
  73.  * Revision 2.1  92/04/21  17:13:52  rwd
  74.  * BSDSS
  75.  * 
  76.  *
  77.  */
  78.  
  79. /*
  80.  * Copyright (c) 1980, 1986 Regents of the University of California.
  81.  * All rights reserved.
  82.  *
  83.  * Redistribution and use in source and binary forms, with or without
  84.  * modification, are permitted provided that the following conditions
  85.  * are met:
  86.  * 1. Redistributions of source code must retain the above copyright
  87.  *    notice, this list of conditions and the following disclaimer.
  88.  * 2. Redistributions in binary form must reproduce the above copyright
  89.  *    notice, this list of conditions and the following disclaimer in the
  90.  *    documentation and/or other materials provided with the distribution.
  91.  * 3. All advertising materials mentioning features or use of this software
  92.  *    must display the following acknowledgement:
  93.  *    This product includes software developed by the University of
  94.  *    California, Berkeley and its contributors.
  95.  * 4. Neither the name of the University nor the names of its contributors
  96.  *    may be used to endorse or promote products derived from this software
  97.  *    without specific prior written permission.
  98.  *
  99.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  100.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  101.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  102.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  103.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  104.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  105.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  106.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  107.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  108.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  109.  * SUCH DAMAGE.
  110.  *
  111.  *    @(#)route.h    7.13 (Berkeley) 4/25/91
  112.  */
  113.  
  114. #ifndef NET_ROUTE_H
  115. #define NET_ROUTE_H
  116.  
  117. /*
  118.  * Kernel resident routing tables.
  119.  * 
  120.  * The routing tables are initialized when interface addresses
  121.  * are set by making entries for all directly connected interfaces.
  122.  */
  123.  
  124. /*
  125.  * A route consists of a destination address and a reference
  126.  * to a routing entry.  These are often held by protocols
  127.  * in their control blocks, e.g. inpcb.
  128.  */
  129. struct route {
  130.     struct    rtentry *ro_rt;
  131.     struct    sockaddr ro_dst;
  132. };
  133.  
  134. /*
  135.  * These numbers are used by reliable protocols for determining
  136.  * retransmission behavior and are included in the routing structure.
  137.  */
  138. struct rt_metrics {
  139.     u_long    rmx_locks;    /* Kernel must leave these values alone */
  140.     u_long    rmx_mtu;    /* MTU for this path */
  141.     u_long    rmx_hopcount;    /* max hops expected */
  142.     u_long    rmx_expire;    /* lifetime for route, e.g. redirect */
  143.     u_long    rmx_recvpipe;    /* inbound delay-bandwith product */
  144.     u_long    rmx_sendpipe;    /* outbound delay-bandwith product */
  145.     u_long    rmx_ssthresh;    /* outbound gateway buffer limit */
  146.     u_long    rmx_rtt;    /* estimated round trip time */
  147.     u_long    rmx_rttvar;    /* estimated rtt variance */
  148. };
  149.  
  150. /*
  151.  * rmx_rtt and rmx_rttvar are stored as microseconds;
  152.  * RTTTOPRHZ(rtt) converts to a value suitable for use
  153.  * by a protocol slowtimo counter.
  154.  */
  155. #define    RTM_RTTUNIT    1000000    /* units for rtt, rttvar, as units per sec */
  156. #define    RTTTOPRHZ(r)    ((r) / (RTM_RTTUNIT / PR_SLOWHZ))
  157.  
  158. /*
  159.  * We distinguish between routes to hosts and routes to networks,
  160.  * preferring the former if available.  For each route we infer
  161.  * the interface to use from the gateway address supplied when
  162.  * the route was entered.  Routes that forward packets through
  163.  * gateways are marked so that the output routines know to address the
  164.  * gateway rather than the ultimate destination.
  165.  */
  166. #ifdef KERNEL
  167. #ifndef RNF_NORMAL
  168. #include <net/radix.h>
  169. #endif
  170. struct rtentry {
  171.     struct    radix_node rt_nodes[2];    /* tree glue, and other values */
  172. #define    rt_key(r)    ((struct sockaddr *)((r)->rt_nodes->rn_key))
  173. #define    rt_mask(r)    ((struct sockaddr *)((r)->rt_nodes->rn_mask))
  174.     struct    sockaddr *rt_gateway;    /* value */
  175.     short    rt_flags;        /* up/down?, host/net */
  176.     short    rt_refcnt;        /* # held references */
  177.     u_long    rt_use;            /* raw # packets forwarded */
  178.     struct    ifnet *rt_ifp;        /* the answer: interface to use */
  179.     struct    ifaddr *rt_ifa;        /* the answer: interface to use */
  180.     struct    sockaddr *rt_genmask;    /* for generation of cloned routes */
  181.     caddr_t    rt_llinfo;        /* pointer to link level info cache */
  182.     struct    rt_metrics rt_rmx;    /* metrics used by rx'ing protocols */
  183.     short    rt_idle;        /* easy to tell llayer still live */
  184. };
  185. #endif /* KERNEL */
  186.  
  187. /*
  188.  * Following structure necessary for 4.3 compatibility;
  189.  * We should eventually move it to a compat file.
  190.  */
  191. struct ortentry {
  192.     u_long    rt_hash;        /* to speed lookups */
  193.     struct    sockaddr rt_dst;    /* key */
  194.     struct    sockaddr rt_gateway;    /* value */
  195.     short    rt_flags;        /* up/down?, host/net */
  196.     short    rt_refcnt;        /* # held references */
  197.     u_long    rt_use;            /* raw # packets forwarded */
  198.     struct    ifnet *rt_ifp;        /* the answer: interface to use */
  199. };
  200.  
  201. #define    RTF_UP        0x1        /* route useable */
  202. #define    RTF_GATEWAY    0x2        /* destination is a gateway */
  203. #define    RTF_HOST    0x4        /* host entry (net otherwise) */
  204. #define    RTF_REJECT    0x8        /* host or net unreachable */
  205. #define    RTF_DYNAMIC    0x10        /* created dynamically (by redirect) */
  206. #define    RTF_MODIFIED    0x20        /* modified dynamically (by redirect) */
  207. #define RTF_DONE    0x40        /* message confirmed */
  208. #define RTF_MASK    0x80        /* subnet mask present */
  209. #define RTF_CLONING    0x100        /* generate new routes on use */
  210. #define RTF_XRESOLVE    0x200        /* external daemon resolves name */
  211. #define RTF_LLINFO    0x400        /* generated by ARP or ESIS */
  212. #define RTF_PROTO2    0x4000        /* protocol specific routing flag */
  213. #define RTF_PROTO1    0x8000        /* protocol specific routing flag */
  214.  
  215.  
  216. /*
  217.  * Routing statistics.
  218.  */
  219. struct    rtstat {
  220.     short    rts_badredirect;    /* bogus redirect calls */
  221.     short    rts_dynamic;        /* routes created by redirects */
  222.     short    rts_newgateway;        /* routes modified by redirects */
  223.     short    rts_unreach;        /* lookups which failed */
  224.     short    rts_wildcard;        /* lookups satisfied by a wildcard */
  225. };
  226. /*
  227.  * Structures for routing messages.
  228.  */
  229. struct rt_msghdr {
  230.     u_short    rtm_msglen;    /* to skip over non-understood messages */
  231.     u_char    rtm_version;    /* future binary compatability */
  232.     u_char    rtm_type;    /* message type */
  233.     u_short    rtm_index;    /* index for associated ifp */
  234.     pid_t    rtm_pid;    /* identify sender */
  235.     int    rtm_addrs;    /* bitmask identifying sockaddrs in msg */
  236.     int    rtm_seq;    /* for sender to identify action */
  237.     int    rtm_errno;    /* why failed */
  238.     int    rtm_flags;    /* flags, incl. kern & message, e.g. DONE */
  239.     int    rtm_use;    /* from rtentry */
  240.     u_long    rtm_inits;    /* which metrics we are initializing */
  241.     struct    rt_metrics rtm_rmx; /* metrics themselves */
  242. };
  243.  
  244. struct route_cb {
  245.     int    ip_count;
  246.     int    ns_count;
  247.     int    iso_count;
  248.     int    any_count;
  249. };
  250. #define RTM_VERSION    2    /* Up the ante and ignore older versions */
  251.  
  252. #define RTM_ADD        0x1    /* Add Route */
  253. #define RTM_DELETE    0x2    /* Delete Route */
  254. #define RTM_CHANGE    0x3    /* Change Metrics or flags */
  255. #define RTM_GET        0x4    /* Report Metrics */
  256. #define RTM_LOSING    0x5    /* Kernel Suspects Partitioning */
  257. #define RTM_REDIRECT    0x6    /* Told to use different route */
  258. #define RTM_MISS    0x7    /* Lookup failed on this address */
  259. #define RTM_LOCK    0x8    /* fix specified metrics */
  260. #define RTM_OLDADD    0x9    /* caused by SIOCADDRT */
  261. #define RTM_OLDDEL    0xa    /* caused by SIOCDELRT */
  262. #define RTM_RESOLVE    0xb    /* req to resolve dst to LL addr */
  263.  
  264. #define RTV_MTU        0x1    /* init or lock _mtu */
  265. #define RTV_HOPCOUNT    0x2    /* init or lock _hopcount */
  266. #define RTV_EXPIRE    0x4    /* init or lock _hopcount */
  267. #define RTV_RPIPE    0x8    /* init or lock _recvpipe */
  268. #define RTV_SPIPE    0x10    /* init or lock _sendpipe */
  269. #define RTV_SSTHRESH    0x20    /* init or lock _ssthresh */
  270. #define RTV_RTT        0x40    /* init or lock _rtt */
  271. #define RTV_RTTVAR    0x80    /* init or lock _rttvar */
  272.  
  273. #define RTA_DST        0x1    /* destination sockaddr present */
  274. #define RTA_GATEWAY    0x2    /* gateway sockaddr present */
  275. #define RTA_NETMASK    0x4    /* netmask sockaddr present */
  276. #define RTA_GENMASK    0x8    /* cloning mask sockaddr present */
  277. #define RTA_IFP        0x10    /* interface name sockaddr present */
  278. #define RTA_IFA        0x20    /* interface addr sockaddr present */
  279. #define RTA_AUTHOR    0x40    /* sockaddr for author of redirect */
  280.  
  281. #ifdef KERNEL
  282. extern struct route_cb route_cb;
  283.  
  284. #define    RTFREE(rt) \
  285.     if ((rt)->rt_refcnt <= 1) \
  286.         rtfree(rt); \
  287.     else \
  288.         (rt)->rt_refcnt--;
  289.  
  290. extern struct    rtstat    rtstat;
  291.  
  292. void rtinitheads(void);
  293. void rtalloc(struct route * ro);
  294. struct rtentry * rtalloc1(struct sockaddr * dst, int report);
  295. void rtfree(struct rtentry * rt);
  296. void rtredirect(struct sockaddr * dst, struct sockaddr * gateway,
  297.                struct sockaddr * netmask, int flags,
  298.                struct sockaddr * src, struct rtentry ** rtp);
  299. int rtioctl(int req, caddr_t data);
  300. struct ifaddr * ifa_ifwithroute(int flags, struct sockaddr * dst,
  301.                                 struct sockaddr * gateway);
  302. int rtrequest(int req, struct sockaddr * dst, struct sockaddr * gateway,
  303.               struct sockaddr * netmask, int flags, struct rtentry ** ret_nrt);
  304. void rt_maskedcopy(struct sockaddr * src, struct sockaddr * dst,
  305.                   struct sockaddr * netmask);
  306. int rtinit(struct ifaddr * ifa, int cmd, int flags);
  307.  
  308. #endif /* KERNEL */
  309.  
  310. #endif /* !NET_ROUTE_H */
  311.